package day02;

import org.junit.Test;
import work.JDBCUtils;
import work.MyDatasource;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class MyDatasourceTest {

    @Test
    public void demo() {
        MyDatasource ds = new MyDatasource();
        // 初始化值
        Connection conn = null;
        ResultSet rs = null;
        PreparedStatement pst = null;
        try {
            // 获取连接
//            conn = JDBCUtils.getConnection();
            conn=ds.getConnection();
            String sql = "select * from exam";
            // 获取发送sql的对象
            pst = conn.prepareStatement(sql);
            // 执行sql
            rs = pst.executeQuery();
            //处理结果
            while(rs.next())
            {
                //取出数据
                int id = rs.getInt("id");
                String name = rs.getString("name");
                String chinese = rs.getString("chinese");
                //输出
                System.out.println(id+"==="+name+"----"+chinese);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally
        {
            JDBCUtils.release(null, pst, rs);
            ds.backPool(conn);
        }
    }
}

